#include "smogthread.h"

smogthread::smogthread(QObject *parent) : QObject(parent)
{
    socket = new QTcpSocket;
     connect(socket, &QTcpSocket::readyRead, this, [this]() {
         QByteArray data = socket->readAll();
         emit smogDataReceived(QString(data));
     });
 }
 smogthread::~smogthread()
 {
     socket->disconnectFromHost();
     socket->deleteLater(); // 确保 socket 被删除
 }

 void smogthread::run()
 {
     socket->connectToHost("192.168.2.56", 8884);
     if (!socket->waitForConnected(3000)) {
         qDebug() << "连接失败<Get smog  Port:8884>：" << socket->errorString();
         return; // 连接失败时退出
     }

 }
